<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script type='text/javascript' src='../js/vue.js'></script>
</head>

<body>
    <!-- 
        computed计算属性不能开启异步任务;
        watch可以开启异步任务

        computed和watch
            computed的功能，watch都能实现
            watch能完成的，computed不一定
                所有被Vue管理的函数，最好写成普通函数，this才指向vm
                所有不被Vue所管理的函数（定时器、ajax回调函数）写成箭头函数，这样的this才指向vm或组件实例对象

     -->
    <div id="root">
        姓：<input type='text' v-model='firstName' /><br /><br />
        名：<input type='text' v-model='lastName' /><br /><br />
        名字：<span>{{fullName}}</span>

    </div>
    <script>
        const vm = new Vue({
            el: '#root',
            data: {
                firstName: 'SONG',
                lastName: 'YAXUAN',
                fullName: 'SONG-YAXUAN'
            },
            watch: {
                firstName(newValue) {
                    this.fullName = newValue + '-' + this.lastName
                },
                lastName(newValue) {
                    this.fullName = this.firstName + '-' + newValue
                }
            }

        })
        console.log(vm);
    </script>
</body>

</html>